package models;

import play.*;
import play.data.validation.Required;
import play.db.jpa.*;
import validation.Unique;

import javax.persistence.*;
import java.util.*;
/**
 * 权限（对控制器Action方法全称的包装）
 * @author yujie
 *
 */
@Entity
public class QuanXian extends Model  implements Comparable<QuanXian> {
	
	public QuanXian(String caoZuo, String shuoMing) {
		super();
		this.caoZuo = caoZuo;
		this.shuoMing = shuoMing;
	}

	/**
	 * 操作：控制器Action方法全称（非空，唯一）
	 */
	@Required
	@Unique(message = "QuanXian.caoZuo.Unique")
	public String caoZuo;
	
	/**
	 * 说明：对权限操作的说明
	 */
	@Required
	@Unique(message = "QuanXian.shuoMing.Unique")
	public String shuoMing;
	
	/**
	 * 根据操作名获得权限对象
	 * @param caoZuo
	 * @return
	 */
	public static QuanXian findByCaoZuo(String caoZuo) {
		return QuanXian.find("byCaoZuo", caoZuo).first();
	}
	/**
	 * 根据Action方法全称比较两个权限是否相同
	 */
	@Override
	public int compareTo(QuanXian qiTa) {
		return this.caoZuo.compareTo(qiTa.caoZuo);
	}

	@Override
	public String toString() {
		return shuoMing;
	}

}
